{% for frontend in haproxy_frontend %}
frontend {{ frontend.name }}
{% if frontend.description is defined %}
  description {{ frontend.description }}
{% endif %}

{% for bind in frontend.bind %}
  bind {{ bind.listen }}{% for param in bind.param | default([]) %} {{ param }}{% endfor %}

{% endfor %}

{% if frontend.bind_process is defined %}
  bind-process {{ frontend.bind_process | join(' ') }}
{% endif %}

  mode {{ frontend.mode }}

{% if frontend.maxconn is defined %}
  maxconn {{ frontend.maxconn }}
{% endif %}

{% for stick in frontend.stick | default([]) %}
  stick-table {{ stick.table }}
{% endfor %}

{% for option in frontend.option | default([]) %}
  option {{ option }}
{% endfor %}

{% for option in frontend.no_option | default([]) %}
  no option {{ option }}
{% endfor %}

{% if frontend.logformat is defined %}
  log-format {{ frontend.logformat }}
{% endif %}

{% if frontend.no_log | default(false) == true %}
  no log
{% endif %}

{% for timeout in frontend.timeout | default([]) %}
  timeout {{ timeout.type }} {{ timeout.timeout }}
{% endfor %}

{% for acl in frontend.acl | default([]) %}
  acl {{ acl.string }}
{% endfor %}

{% for capture in frontend.capture | default([]) %}
  capture {{ capture.type }} {{ capture.name }} len {{ capture.length }}
{% endfor %}

{% for tcp_request_inspect_delay in frontend.tcp_request_inspect_delay | default([]) %}
  tcp-request inspect-delay {{ tcp_request_inspect_delay.timeout }}

{% endfor %}

{% for tcp_request_connection in frontend.tcp_request_connection | default([]) %}
  tcp-request connection {{ tcp_request_connection.action }}{% if tcp_request_connection.cond is defined %} {{ tcp_request_connection.cond }}{% endif %}

{% endfor %}

{% for tcp_request_content in frontend.tcp_request_content | default([]) %}
  tcp-request content {{ tcp_request_content.action }}{% if tcp_request_content.cond is defined %} {{ tcp_request_content.cond }}{% endif %}

{% endfor %}

{% for tcp_request_session in frontend.tcp_request_session | default([]) %}
  tcp-request session {{ tcp_request_session.action }}{% if tcp_request_session.cond is defined %} {{ tcp_request_session.cond }}{% endif %}

{% endfor %}

{% for http_request in frontend.http_request | default([]) %}
  http-request {{ http_request.action }}{% if http_request.param is defined %} {{ http_request.param }}{% endif %}{% if http_request.cond is defined %} {{ http_request.cond }}{% endif %}

{% endfor %}

{% for http_response in frontend.http_response | default([]) %}
  http-response {{ http_response.action }}{% if http_response.param is defined %} {{ http_response.param }}{% endif %}{% if http_response.cond is defined %} {{ http_response.cond }}{% endif %}

{% endfor %}

{% for action in ['reqadd', 'rspadd'] %}
{% for params in frontend[action] | default([]) %}
  {{ action }} {{ params.string }}{% if params.cond is defined %} {{ params.cond }}{% endif %}

{% endfor %}
{% endfor %}

{% for action in ['reqdel', 'reqidel', 'rspdel', 'rspidel'] %}
{% for params in frontend[action] | default([]) %}
  {{ action }} {{ params.search }}{% if params.cond is defined %} {{ params.cond }}{% endif %}

{% endfor %}
{% endfor %}

{% for action in ['reqrep', 'reqirep', 'rsprep', 'rspirep'] %}
{% for params in frontend[action] | default([]) %}
  {{ action }} {{ params.search }} {{ params.string }}{% if params.cond is defined %} {{ params.cond }}{% endif %}

{% endfor %}
{% endfor %}

{% for redirect in frontend.redirect | default([]) %}
  redirect {{ redirect.string }}{% if redirect.cond is defined %} {{ redirect.cond }}{% endif %}

{% endfor %}

{% for compression in frontend.compression | default([]) %}
  compression {{ compression.name }} {{ compression.value }}
{% endfor %}

{% if frontend.use_backend is defined %}
{% if frontend.use_backend is iterable and frontend.use_backend is not string %}
{% for use_backend in frontend.use_backend | default([]) %}
  use_backend {{ use_backend }}
{% endfor %}
{% else %}
  use_backend {{ frontend.use_backend }}
{% endif %}
{% endif %}

{% if frontend.default_backend is defined %}
  default_backend {{ frontend.default_backend }}
{% endif %}

{% for errorfile in frontend.errorfile | default([]) %}
  errorfile {{ errorfile.code }} {{ errorfile.file }}
{% endfor %}

{% for line in frontend.raw_options | default([]) %}
  {{ line }}
{% endfor %}
{% endfor %}
